package com.huisou.scheduler;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;

import org.apache.solr.core.SolrResourceLoader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class SolrDataImportProperties
{
	private Properties properties;
	
	public static final String SYNC_ENABLED = "syncEnabled";
	public static final String SYNC_CORES = "syncCores";
	public static final String SERVER = "server";
	public static final String PORT = "port";
	public static final String WEBAPP = "webapp";
	public static final String COMMAND = "command";
	public static final String PERROWS = "perrows";
	public static final String SALEROWS = "salerows";
	public static final String BUYROWS = "buyrows";
	public static final String COMROWS = "comrows";
	public static final String NEWSROWS = "newsrows";
	public static final String ASKROWS = "askrows";
	public static final String FRIROWS = "frirows";
	
	private static final Logger logger = LoggerFactory.getLogger(SolrDataImportProperties.class);
	
	public SolrDataImportProperties()
	{
		loadProperties(true);
	}
	
	public void loadProperties(boolean force)
	{
		try
		{
			SolrResourceLoader loader = new SolrResourceLoader(null);
			logger.info("Instance dir = " + loader.getInstanceDir());
			String configDir = loader.getConfigDir();
			configDir = SolrResourceLoader.normalizeDir(configDir);
			if (force || properties == null)
			{
				properties = new Properties();
				String dataImportPropertiesPath = configDir + File.separator + "dataimport.properties";
				
				FileInputStream fis = new FileInputStream(dataImportPropertiesPath);
				properties.load(fis);
			}
		}
		catch (Exception e)
		{
			logger.error("读取索引更新属性文件失败", e);
		}
	}
	
	public String getProperty(String key)
	{
		return properties.getProperty(key);
	}
}
